#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc3_tmom_fdif.info <<'%EOF%'
   cc3_tmom_fdif
   --------------
   Molecule:         He2 in C1
   Wave Function:    CCSD and CC3 / cc-pVDZ
   Test Purpose:     finite difference on transition moments
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc3_tmom_fdif.mol <<'%EOF%'
BASIS
cc-pVDZ


    1    0  Y  X  Z   1.00D-15
        2.0   2
He    0.0000000000000000  0.0000000000000000 0.00000000000000000      
He    0.0000000000000000  0.0000000000000000 1.50000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc3_tmom_fdif.dal <<'%EOF%'
**DALTON
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
**SIRIUS
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.RESTART
.CCSD
.CC3
.THRENR
 1.0d-13
.THRLEQ
 1.0d-13
.FIELD
 0.000001
 ZDIPLEN
*CCEXCI
.NCCEXCI
 4 
.THREXC
 1.0d-12
.R3DIIS
*CCOPA
.DIPLEN
*NODDY
.GMAT
.FMAT
.FAMAT
.XIDEN
.ETADEN
.AAMAT
.FINDIF
**END OF DALTON
%EOF%
#######################################################################


#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc3_tmom_fdif.check
cat >>cc3_tmom_fdif.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CC2 energies:
CRIT1=`$GREP "Final * HF energy:" $log | $GREP "\-5.3614342832" | wc -l`
CRIT2=`$GREP "Total CCSD * energy: * \-5.4317351158" $log | wc -l`
CRIT3=`$GREP "Total CC3 * energy:  * \-5.4318045446" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=5
ERROR[1]="ENERGIES NOT CORRECT"

# CCSD excitation energies
CRIT1=`$GREP "\^1A * . * 1 * . * 1\.351930. * . * 36\.7879. * . * 296714\.... * . * 98\.93" $log | wc -l`
CRIT2=`$GREP "\^1A * . * 2 * . * 1\.586139. * . * 43\.1610. * . * 348117\.... * . * 98\.84" $log | wc -l`
CRIT3=`$GREP "\^1A * . * 3 * . * 2\.045322. * . * 55\.6560. * . * 448896\.... * . * 99\.16" $log | wc -l`
CRIT4=`$GREP "\^1A * . * 4 * . * 2\.124874. * . * 57\.8207. * . * 466355\.... * . * 96\.75" $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[2]=4
ERROR[2]="CCSD EXCITATION ENERGIES NOT CORRECT"

# CC3 excitation energies
CRIT1=`$GREP "\^1A * . * 1 * . * 1\.351786. * . * 36\.7839. * . * 296682\.... * . * 98\.92" $log | wc -l`
CRIT2=`$GREP "\^1A * . * 2 * . * 1\.585795. * . * 43\.1516. * . * 348041\.... * . * 98\.83" $log | wc -l`
CRIT3=`$GREP "\^1A * . * 3 * . * 2\.045085. * . * 55\.6496. * . * 448844\.... * . * 99\.14" $log | wc -l`
CRIT4=`$GREP "\^1A * . * 4 * . * 2\.124499. * . * 57\.8105. * . * 466273\.... * . * 96\.67" $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[3]=4
ERROR[3]="CC3 EXCITATION ENERGIES NOT CORRECT"


# CCSD onephoton transition moments:
CRIT1=`$GREP "ZDIPLEN * . * (0|\-|\-0)\.48077965 *. * (0|\-|\-0)\.95231131 *. * (0| )\.45785190" $log | wc -l`
CRIT2=`$GREP "ZDIPLEN * . * (0|\-|\-0)\.0000022. *. * (0|\-|\-0)\.00000457 *. * (0| )\.00000000" $log | wc -l`
CRIT3=`$GREP -m 1 "(Y|X)DIPLEN * . * (0|\-|\-0)\.0000001. *. * (0|\-|\-0)\.00000021 *. * (0| )\.00000000" $log | wc -l`
CRIT4=`$GREP "ZDIPLEN * . * (0|\-|\-0)\.00000150 *. * (0|\-|\-0)\.00000304 *. * (0| )\.00000000" $log | wc -l`
CRIT5=`$GREP "oscillator strength .length gauge. * . * (0| )\.41265595" $log | wc -l`
#CRIT6=`$GREP "oscillator strength .length gauge. * . * (0| )\.00000000" $log | wc -l`
#CRIT7=`$GREP "oscillator strength .length gauge. * . * (0| )\.00000000" $log | wc -l`
#CRIT8=`$GREP "oscillator strength .length gauge. * . * (0| )\.00000000" $log | wc -l`
TEST[4]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[4]=6
ERROR[4]="CCSD ONEPHOTON TRANSITION MOMENTS NOT CORRECT"


# CC3 onephoton transition moments:
CRIT1=`$GREP "ZDIPLEN * . * (0|\-|\-0)\.48079338 *. * (0|\-|\-0)\.95174601 *. * (0| )\.45759318" $log | wc -l`
CRIT2=`$GREP "ZDIPLEN * . * (0|\-|\-0)\.0000022. *. * (0|\-|\-0)\.00000457 *. * (0| )\.00000000" $log | wc -l`
CRIT3=`$GREP -m 1 "(Y|X)DIPLEN * . * (0|\-|\-0)\.0000001. *. * (0|\-|\-0)\.00000021 *. * (0| )\.00000000" $log | wc -l`
CRIT4=`$GREP "ZDIPLEN * . * (0|\-|\-0)\.00000151 *. * (0|\-|\-0)\.00000306 *. * (0| )\.00000000" $log | wc -l`
CRIT5=`$GREP "oscillator strength .length gauge. * . * (0| )\.41237882" $log | wc -l`
#CRIT6=`$GREP "oscillator strength .length gauge. * . * (0| )\.00000000" $log | wc -l`
#CRIT7=`$GREP "oscillator strength .length gauge. * . * (0| )\.00000000" $log | wc -l`
#CRIT8=`$GREP "oscillator strength .length gauge. * . * (0| )\.00000000" $log | wc -l`
#TEST[5]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8`
TEST[5]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[5]=6
ERROR[5]="CC3 ONEPHOTON TRANSITION MOMENTS NOT CORRECT"


PASSED=1
for i in 1 2 3 4 5
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
#######################################################################
